//
//  BaseTableViewController.m
//  wechat
//
//  Created by 桑赐相 on 2017/12/18.
//  Copyright © 2017年 桑赐相. All rights reserved.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()

/**  */
@property (nonatomic,strong) UIView *normalView;
/**  */
@property (nonatomic,strong) UIImageView *imageView;
/**  */
@property (nonatomic,strong) UILabel *infoLabel;
@end

@implementation BaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.page = 0;
    self.view.backgroundColor = ViewBackgroundColor;
    self.tableView.backgroundColor = ViewBackgroundColor;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(down_refreshData)];
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    [self initSubView];
}
-(void)initSubView{
    
    self.normalView = [UIView new];
    self.normalView.hidden = YES;
    [self.tableView addSubview:self.normalView];
    
    self.imageView = [UIImageView new];
    self.imageView.image = [UIImage imageNamed:@"nomore_data"];
    [self.normalView addSubview:self.imageView];
    
    self.infoLabel = [UILabel new];
    self.infoLabel.textColor = HexRGB(0x888888);
    self.infoLabel.text = @"没有内容";
    [self.normalView addSubview:self.infoLabel];
    
    [self.normalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.tableView);
        make.centerY.equalTo(self.tableView).offset(-50);
    }];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.normalView);
        make.width.height.mas_offset(80);
    }];
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).offset(10);
        make.centerX.equalTo(self.normalView);
    }];
}

-(void)showNoDataViewWithMessage:(NSString *)msg{
    self.infoLabel.text = msg;
    self.normalView.hidden = NO;
}

-(void)hideNoDataView{
    self.normalView.hidden = YES;
}

-(void)down_refreshData{
    [self.tableView.mj_header endRefreshing];
}

-(void)loadMoreData{
    [self.tableView.mj_footer endRefreshing];
}

-(void)reloadData{
    [self.tableView reloadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [UITableViewCell new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}


-(void)pushViewController:(UIViewController *)viewController{
    viewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:viewController animated:YES];
}
-(void)popViewController{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)dismissViewController{
    [self dismissViewControllerAnimated:YES completion:nil];
}


-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

@end

